package com.sinven.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.sinven.pojo.Article;
import com.sinven.pojo.Comment;
import com.sinven.pojo.User;
import com.sinven.service.ArticleService;
import com.sinven.service.CommentService;
import com.sinven.service.CommentServiceImpl;
import com.sinven.service.UserService;

@Controller
public class detailsController {

	@Autowired
	private ArticleService articleServiceImpl;
	@Autowired
	private CommentService CommentServiceImpl;
	@Autowired
	private UserService UserServiceImpl;

	@RequestMapping({ "details" })
	public String article(Model model, @RequestParam(value = "a_id") int a_id) {
		System.out.println(a_id);
		try {
			articleServiceImpl.AddPageview(a_id);
			Article articleContent = articleServiceImpl.SelectArticleContent(a_id);
			List<Comment> selectComentCountBySelf = CommentServiceImpl.SelectComentCountBySelf(a_id);
			System.out.println(articleContent.getA_authorId().getU_id()+"德玛西亚");
			User selectUserById = UserServiceImpl.SelectUserById(articleContent.getA_authorId().getU_id());
			model.addAttribute("ArticleContent", articleContent);
			model.addAttribute("selectComentCountBySelf", selectComentCountBySelf);
			model.addAttribute("selectUserById", selectUserById);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "pages/details";
	}

}
